home *** CD-ROM | disk | FTP | other *** search
- Path: GIMLI.genias.de!usenet
- From: Andreas Haas <andreas>
- Newsgroups: comp.lang.c
- Subject: Re: 2d array of pointers to structures ?
- Date: 16 Apr 1996 12:34:01 GMT
- Organization: GENIAS Software GmbH
- Message-ID: <4l043p$b05@GIMLI.genias.de>
- References: <829573448snz@willen.demon.co.uk>
- NNTP-Posting-Host: balin.genias.de
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.1N (X11; I; SunOS 4.1.2 sun4c)
- X-URL: news:829573448snz@willen.demon.co.uk
-
- Adrian Parker <adrian@willen.demon.co.uk> wrote:
- >
- >I need to keep a 2d array of structures, which I have to do at runtime
- >as they array could be quite big, and the compiler can't cope with
- >static arrays of the required size.
- >
-
- Try this:
-
- T_loc **lpp = NULL;
-
- lpp = (T_loc **)malloc(cols*sizeof(T_loc *));
- for (i=0; i<rows; i++)
- lpp[i] = (T_loc *)malloc(rows*sizeof(T_loc));
-
-
- now you can access these entries as follows:
-
- lpp[i][j].id = 0;
- lpp[i][j].colour = GREEN;
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Andreas Haas
- GENIAS Software GmbH | Email: andreas@genias.de
- Erzgebirgstr. 2 B | Tel.: ++49 +9401 9200-0/41
- D-93073 Neutraubling/Germany | FAX: ++49 +9401 9200-92
- http://www.genias.de/ |
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-